home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / glibc108.gz / glibc108 / glibc-1.08.1 / sysdeps / mach / hurd / i386 / exc2signal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-05  |  3.9 KB  |  163 lines

  1. /* Translate Mach exception codes into signal numbers.  i386 version.
  2. Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4.  
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9.  
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with the GNU C Library; see the file COPYING.LIB.  If
  17. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  18. Cambridge, MA 02139, USA.  */
  19.  
  20. #include <hurd.h>
  21. #include <hurd/signal.h>
  22. #include <mach/exception.h>
  23.  
  24. /* Translate the Mach exception codes, as received in an `exception_raise' RPC,
  25.    into a signal number and signal subcode.  */
  26.  
  27. void
  28. _hurd_exception2signal (int exception, int code, int subcode,
  29.             int *signo, int *sigcode)
  30. {
  31.   switch (exception)
  32.     {
  33.     default:
  34.       *signo = SIGIOT;
  35.       *sigcode = exception;
  36.       break;
  37.       
  38.     case EXC_BAD_ACCESS:
  39.       if (code == KERN_PROTECTION_FAILURE)
  40.     *signo = SIGSEGV;
  41.       else
  42.     *signo = SIGBUS;
  43.       *sigcode = subcode;
  44.       break;
  45.  
  46.     case EXC_BAD_INSTRUCTION:
  47.       *signo = SIGILL;
  48.       if (code == EXC_I386_INVOP)
  49.     *sigcode = ILL_INVOPR_FAULT;
  50.       else if (code == EXC_I386_STKFLT)
  51.     *sigcode = ILL_STACK_FAULT;
  52.       else
  53.     *sigcode = 0;
  54.       break;
  55.       
  56.     case EXC_ARITHMETIC:
  57.       switch (code)
  58.     {
  59.     case EXC_I386_DIV:    /* integer divide by zero */
  60.       *signo = SIGFPE;
  61.       *sigcode = FPE_INTDIV_FAULT;
  62.       break;
  63.       
  64.     case EXC_I386_INTO:    /* integer overflow */
  65.       *signo = SIGFPE;
  66.       *sigcode = FPE_INTOVF_TRAP;
  67.       break;
  68.  
  69.       /* These aren't anywhere documented or used in Mach 3.0.  */
  70.     case EXC_I386_NOEXT:
  71.     case EXC_I386_EXTOVR:
  72.     default:
  73.       *signo = SIGFPE;
  74.       *sigcode = 0;
  75.       break;
  76.  
  77.     case EXC_I386_EXTERR:
  78.       /* Subcode is the fp_status word saved by the hardware.
  79.          Give an error code corresponding to the first bit set.  */
  80.       if (subcode & FPS_IE)
  81.         {
  82.           *signo = SIGILL;
  83.           *sigcode = ILL_FPEOPR_FAULT;
  84.         }
  85.       else if (subcode & FPS_DE)
  86.         {
  87.           *signo = SIGFPE;
  88.           *sigcode = FPE_FLTDNR_FAULT;
  89.         }
  90.       else if (subcode & FPS_ZE)
  91.         {
  92.           *signo = SIGFPE;
  93.           *sigcode = FPE_FLTDIV_FAULT;
  94.         }
  95.       else if (subcode & FPS_OE)
  96.         {
  97.           *signo = SIGFPE;
  98.           *sigcode = FPE_FLTOVF_FAULT;
  99.         }
  100.       else if (subcode & FPS_UE)
  101.         {
  102.           *signo = SIGFPE;
  103.           *sigcode = FPE_FLTUND_FAULT;
  104.         }
  105.       else if (subcode & FPS_PE)
  106.         {
  107.           *signo = SIGFPE;
  108.           *sigcode = FPE_FLTINX_FAULT;
  109.         }
  110.       else
  111.         {
  112.           *signo = SIGFPE;
  113.           *sigcode = 0;
  114.         }
  115.       break;
  116.  
  117.       /* These two can only be arithmetic exceptions if we 
  118.          are in V86 mode, which sounds like emulation to me.
  119.          (See Mach 3.0 i386/trap.c.)  */
  120.     case EXC_I386_EMERR:
  121.       *signo = SIGFPE;
  122.       *sigcode = FPE_EMERR_FAULT;
  123.       break;
  124.     case EXC_I386_BOUND:
  125.       *signo = SIGFPE;
  126.       *sigcode = FPE_EMBND_FAULT;
  127.       break;
  128.     }
  129.       break;
  130.  
  131.     case EXC_EMULATION:        
  132.       /* 3.0 doesn't give this one, why, I don't know.  */
  133.       *signo = SIGEMT;
  134.       *sigcode = 0;
  135.       break;
  136.  
  137.     case EXC_SOFTWARE:
  138.       /* The only time we get this in Mach 3.0
  139.      is for an out of bounds trap.  */
  140.       if (code == EXC_I386_BOUND)
  141.     {
  142.       *signo = SIGFPE;
  143.       *sigcode = FPE_SUBRNG_FAULT;
  144.     }
  145.       else
  146.     {
  147.       *signo = SIGEMT;
  148.       *sigcode = 0;
  149.     }
  150.       break;
  151.       
  152.     case EXC_BREAKPOINT:
  153.       *signo = SIGTRAP;
  154.       if (code == EXC_I386_SGL)
  155.     *sigcode = DBG_SINGLE_TRAP;
  156.       else if (code == EXC_I386_BPT)
  157.     *sigcode = DBG_BRKPNT_FAULT;
  158.       else
  159.     *sigcode = 0;
  160.       break;
  161.     }
  162. }
  163.